package com.heima.admin.controller.v1;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.heima.admin.service.AdChannelService;
import com.heima.apis.Admin.AdChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Project：heima-leadnews
 * @Author：fangkui
 * @Date：2021/1/23
 */

@Slf4j // 一般会在重要方法部分把参数做日志打印
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService adChannelService;

    @Override
    @PostMapping("list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto channelDto) {
        return adChannelService.findByNameAndPage(channelDto);
    }

    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel adChannel) {
        log.info("mothod is save,parms is {}",adChannel);
        //log.warn(""); //对异常的日志打印
        return adChannelService.insert(adChannel);
    }

    @Override
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        log.info("mothod is update,parms is {}",adChannel);
        return adChannelService.update(adChannel);
    }

    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adChannelService.deleteById(id);
    }
}
